<?php

/**
 * 
 * @author guibinyu
 * @date 2017-06-15 04:14:50
 */
class Custom
{
    
   private $params;
   private $Wechat;
   private $openid;
   public function __construct($Wechat)
    {
        $this->Wechat = $Wechat;
        $this->openid = 'oYVyYw2BzLX8eJ1I-oCDSN6z4avI';
    }
    
    
    public function addKfaccount()
    {
        $data = array("kf_account" => 'test1@test', "nickname" => '客服1', "password" => md5('123456'));
        $result = $this->Wechat->CustomAccount->addAccount($data);
        return $result;
    }
    public function updateKfaccount()
    {
        $data = array("kf_account" => 'test1@test', "nickname" => '客服1', "password" => md5('123456'));
        $result = $this->Wechat->CustomAccount->updateAccount($data) ;
        return $result;
    }
    public function deleteKfaccount()
    {
         $account = 'test1@test';
        $result = $this->Wechat->CustomAccount->deleteAccount($account);
        return $result;
    }
    public function setKfaccount()
    {
        $account = 'test1@test';
        $imgfile = WECHATSDK_MATERIAL_PATH."0.jpg";
        
        $result = $this->Wechat->CustomAccount->setAccountImg($account, $imgfile);
        return $result;
    }
    public function getKflist()
    {
        $result = $this->Wechat->CustomAccount->getAccountList();
        return $result;
    }
     public function getOnlineKFlist()
    {
        $result = $this->Wechat->CustomAccount->getOnlineList();
        return $result;
    }
     public function inviteworker()
    {
        $data = array("kf_account" => 'test1@test', "invite_wx" => 'xx');
        $result = $this->Wechat->CustomAccount->inviteworker( $data);
        return $result;
    }
    
     public function createSession()
    {
        $data = array("openid" => 'test1@test', "kf_account" => 'test1@test','text'=>'xx');
        $result = $this->Wechat->CustomSession->createSession($data);
        return $result;
    }
     public function closeSession()
    {
        $data = array("openid" => 'test1@test', "kf_account" => 'test1@test','text'=>'xx');
        $result = $this->Wechat->CustomSession->closeSession($data);
        return $result;
    }
     public function getSession()
    {
        $openid = 'test1@test';
        $result = $this->Wechat->CustomSession->getSession($openid);
        return $result;
    }
     public function getSessionList()
    {
        $kf_account = 'test1@test';
        $result = $this->Wechat->CustomSession->getSessionList($kf_account);
        return $result;
    }
    
    
     public function getWait()
    {
        $result = $this->Wechat->CustomSession->getWait();
        return $result;
    }
    
    public function getRecordMessage()
    {
         $data = array(
//             'starttime' =>'',
//             'endtime' =>'',
             'msgid' => 1,
             'number' => 1000,
         );
        $result = $this->Wechat->CustomMessage->getRecordMessage($data);
        return $result;
    }
    
    public function sendtext()
    {
        $text = "Hello World";
        $result = $this->Wechat->CustomMessage->setToUser($this->openid)->text($text)->send();
        return $result;
    }
     public function sendimage()
    {
        $media_id = "tm0D20ZrIxNCja3xm6dVBTCoYwn-OVaprhMAImBIoGA";
        $result = $this->Wechat->CustomMessage->setToUser($this->openid)->image($media_id)->send();
        return $result;
    }
     public function sendvoice()
    {
        $media_id = "tm0D20ZrIxNCja3xm6dVBUfveZgQA7LwcN5V8_L3-zE";
        $result = $this->Wechat->CustomMessage->setToUser($this->openid)->voice($media_id)->send();
        return $result;
    }
     public function sendvideo()
    {
         $data = array(
                'media_id'     => 'tm0D20ZrIxNCja3xm6dVBWLzSXH5XJ0P4NksH0T8rHE',
                'thumb_media_id'  => 'tm0D20ZrIxNCja3xm6dVBTCoYwn-OVaprhMAImBIoGA',
                'title' => '标题xx',
                'description'=> '描述xx',
        );
        $result = $this->Wechat->CustomMessage
                ->setToUser($this->openid)
                ->video($data)
                ->send();
        return $result;
    }
     public function sendmusic()
    {
        $music = array(
                'title'       => '标题xx',
                'description' => '描述xx',
                'musicurl'    => 'http://music.baidu.com/?fr=baiduwisehome&ssid=0&from=844b&uid=&pu=sz%401320_2001%2Cta%40iphone_1_10.3_3_603&bd_page_type=1',
                'hqmusicurl'  => 'http://music.baidu.com/?fr=baiduwisehome&ssid=0&from=844b&uid=&pu=sz%401320_2001%2Cta%40iphone_1_10.3_3_603&bd_page_type=1',
                'thumb_media_id'  => 'tm0D20ZrIxNCja3xm6dVBTCoYwn-OVaprhMAImBIoGA'
            );
        $result = $this->Wechat->CustomMessage->setToUser($this->openid)->music($music)->send();
        return $result;
    }
    public function sendnews()
    {
        $news = array(
            array(
                'title' => '标题xx',
                'description' => '描述xx',
                'url' => 'https://www.huxiu.com/',
                'picurl' => 'http://mmbiz.qpic.cn/mmbiz_jpg/aADO7uwnt54CQXvkLtQs36Jm2fuH0VkXIClM38YuspbaERkpULGmYDkYIdkDtgOEtaUyQp2e7P9kwicn9s4GicZw/0?wx_fmt=jpeg3'
            )
        );
//        $data['narticles'] =  $news;
        $result = $this->Wechat->CustomMessage->setToUser($this->openid)->news($news)->send();
        return $result;
    }
     public function sendmpnews()
    {
        $media_id = "tm0D20ZrIxNCja3xm6dVBVhURDYx6XVGeEnrpXOtHXs";
        $result = $this->Wechat->CustomMessage->setToUser($this->openid)->mpnews($media_id)->send();
        return $result;
    }
     public function sendwxcard()
    {
        $card_id = "Hello World";
        $result = $this->Wechat->CustomMessage->setToUser($this->openid)->wxcard($card_id)->send();
        return $result;
    }
    public function __call($name, $arguments)
    {
        exit("Test does not have [{$name}] method !");
    }
     
//index, view, create, update, delete, options
}